package leetcodecompetition.D378;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Siantar
 * @Date: 2023-12-31-10:43
 * @Description: 1.0
 */
public class T100184 {
    public int maximumLength(String s) {
        Map<Integer, Integer> map = new HashMap<>();
        int pre = 0, cnt = 0, res = 0;
        for (int c : s.toCharArray()) {
            System.out.println(pre + " " + cnt);
            if (c != pre) {
                //pre  cnt
                for (int i = 0; i < 3; i++) {
                    if (cnt - i <= 0) break;
                    int key = (cnt - i) * 1000 + pre;
                    map.put(key, map.getOrDefault(key, 0) + i + 1);
                }
                pre = c;
                cnt = 1;
            } else {
                cnt++;
            }
        }
        for (int i = 0; i < 3; i++) {
            if (cnt - i <= 0) break;
            int key = (cnt - i) * 1000 + pre;
            System.out.println(cnt + " " + key);
            map.put(key, map.getOrDefault(key, 0) + i + 1);
        }
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            int k = entry.getKey(), v = entry.getValue();
            System.out.println(k + " " + v);
            if (v >= 3) {
                res = Math.max(res, k / 1000);
            }
        }
        return res == 0 ? -1 : 0;
    }
}
